import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import Components from 'unplugin-vue-components/vite'
import { fileURLToPath, URL } from 'node:url';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig({
    plugins: [
        vue(),
        Components({
            dts: 'src/typings/components.d.ts',
            resolvers: [
                NaiveUiResolver()
            ]
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    build: {
        lib: {
            entry: path.resolve(__dirname, 'src/index.ts'),
            name: 'HlTableRender',
            fileName: (format) => `hl-table-render.${format}.js`
        },
        rollupOptions: {
            external: ['vue'],
            output: {
                globals: {
                    vue: 'Vue'
                }
            }
        }
    },
    server: {
        watch: {
            usePolling: true // 确保文件系统变化被检测
        }
    }
})
